package zhoufu.sz.sanxiao_check.inject.modules;

import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.simplexml.SimpleXmlConverterFactory;
import zhoufu.sz.sanxiao_check.App;
import zhoufu.sz.sanxiao_check.protocol.ApkInfoApi;

/**
 * Created by hyc on 16/5/5.
 *
 */
@Module
public class AppModule
{
    private final App _app;
    public AppModule(App app)
    {
        this._app=app;
    }

    @Provides @Singleton App provideApp(){
        return this._app;
    }

    private static final String XMlURL      = "http://192.168.1.252:9002";

    @Singleton
    @Provides
    public ApkInfoApi provideApkInfoApi(SimpleXmlConverterFactory
                                         converterFactory){
        Retrofit retrofit = new Retrofit.Builder().baseUrl(XMlURL)
                .addConverterFactory(converterFactory)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
//                .client(client)
                .build();

        return retrofit.create(ApkInfoApi.class);
    }

    @Provides @Singleton public SimpleXmlConverterFactory provideXmlConverter()
    {
        return SimpleXmlConverterFactory.create();
    }
}

